<!-- 角色列表 -->
<template>
  <div class="">
    <el-card>
      <el-table :data="allRoles" border style="width: 100%">
        <el-table-column :label="$t('msg.role.index')" type="index" width="120">
        </el-table-column>
        <el-table-column :label="$t('msg.role.name')" prop="title">
        </el-table-column>
        <el-table-column :label="$t('msg.role.desc')" prop="describe">
        </el-table-column>
        <el-table-column
          :label="$t('msg.role.action')"
          prop="action"
          width="260"
          #default="{ row }"
        >
          <el-button
            type="primary"
            size="mini"
            @click="onDistributePermissionClick(row)"
            v-permission="['distributePermission']"
          >
            {{ $t('msg.role.assignPermissions') }}
          </el-button>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 角色分配弹出层 -->
    <distribute-permission v-model="visible" :roleId="selectUserId"></distribute-permission>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { roleList } from '@/api/role'
import { watchSwitchLang } from '@/utils/i18n'
import DistributePermission from './components/DistributePermission'

// 获取数据相关
const allRoles = ref([])
const getRoleList = async () => {
  allRoles.value = await roleList()
  console.log(allRoles.value)
}
getRoleList()
watchSwitchLang(() => {
  getRoleList()
})

// 角色分配弹出层相关
const selectUserId = ref('')
const visible = ref(false)
const onDistributePermissionClick = (row) => {
  visible.value = true
  selectUserId.value = row.id
}

</script>
<style lang="scss" scoped>
</style>
